//package com.fingard.dsp.bank.directbank.citi01.util;
//
//import com.alibaba.fastjson.JSON;
//import com.fingard.dsp.bank.directbank.DirectBase;
//import com.sun.jersey.api.client.Client;
//import com.sun.jersey.api.client.ClientResponse;
//import com.sun.jersey.api.client.WebResource;
//import com.sun.jersey.api.client.config.DefaultClientConfig;
//import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
//import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
//import com.sun.org.apache.xml.internal.security.utils.Constants;
//import org.apache.commons.net.util.Base64;
//import org.apache.xml.security.encryption.EncryptedData;
//import org.apache.xml.security.encryption.EncryptedKey;
//import org.apache.xml.security.encryption.XMLCipher;
//import org.apache.xml.security.keys.KeyInfo;
//import org.apache.xml.security.keys.content.X509Data;
//import org.apache.xml.security.keys.content.x509.XMLX509Certificate;
//import org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial;
//import org.apache.xml.security.signature.XMLSignature;
//import org.apache.xml.security.transforms.Transforms;
//import org.apache.xml.security.utils.ElementProxy;
//import org.jose4j.jwe.ContentEncryptionAlgorithmIdentifiers;
//import org.jose4j.jwe.JsonWebEncryption;
//import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers;
//import org.jose4j.jws.AlgorithmIdentifiers;
//import org.jose4j.jws.JsonWebSignature;
//import org.springframework.http.HttpHeaders;
//import org.w3c.dom.Document;
//import org.w3c.dom.Element;
//import org.w3c.dom.Node;
//import org.w3c.dom.NodeList;
//import org.xml.sax.InputSource;
//
//import javax.crypto.Cipher;
//import javax.crypto.KeyGenerator;
//import javax.crypto.SecretKeyFactory;
//import javax.crypto.spec.DESedeKeySpec;
//import javax.crypto.spec.IvParameterSpec;
//import javax.net.ssl.HttpsURLConnection;
//import javax.net.ssl.KeyManagerFactory;
//import javax.net.ssl.SSLContext;
//import javax.ws.rs.core.MediaType;
//import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilderFactory;
//import javax.xml.transform.OutputKeys;
//import javax.xml.transform.Transformer;
//import javax.xml.transform.TransformerFactory;
//import javax.xml.transform.dom.DOMSource;
//import javax.xml.transform.stream.StreamResult;
//import java.io.*;
//import java.net.HttpURLConnection;
//import java.net.InetSocketAddress;
//import java.net.Proxy;
//import java.net.URL;
//import java.security.*;
//import java.security.cert.CertificateFactory;
//import java.security.cert.X509Certificate;
//import java.util.Enumeration;
//
//public class HttpHelper extends DirectBase {
//
//    /** *//**
//     * RSA最大加密明文大小
//     */
//    private static final int MAX_ENCRYPT_BLOCK = 117;
//
//    /** *//**
//     * RSA最大解密密文大小
//     */
//    private static final int MAX_DECRYPT_BLOCK = 128;
//
//    private static String keyStoreFilePath = "E:\\ssl\\heytea_encryp.jks"; //"E:\\ssl\\2019_xicha.jks";
//    private static String keyStorePwd ="123456";
//    private static String clientSignKeyAlias = "1"; //2099证书为：keytea  249证书为：keytea249
//
//
//    private static String citiKeyFileString = "E:\\ssl\\tts.api.citi.com_2019.pem";
//    //花旗加密公钥
//    private static String citiEncryptFileString = "E:\\ssl\\citigroupsoa.xenc.citigroup.com-pub.pem";
//    //花旗签名公钥
//    private static String citiSignFileString  = "E:\\ssl\\citigroupsoa.dsig.citigroup.com-pub.pem";
//   // private static String keyAlias = null;
//
//    public static String EncryptionJSON(String requestPayload) throws Exception{
//        KeyStore ks = null;
//        try {
//            ks = KeyStore.getInstance("JKS");
//        } catch (KeyStoreException e) {
//            e.printStackTrace();
//        }
//        FileInputStream fis = new FileInputStream(keyStoreFilePath);
//        ks.load(fis, keyStorePwd.toCharArray());
//        fis.close();
//        System.out.println(JSON.toJSONString(ks.aliases()));
//
//        PrivateKey privateSignKey = (PrivateKey) ks.getKey("1", keyStorePwd.toCharArray());
//        X509Certificate signCert = (X509Certificate)ks.getCertificate("1");
//     //   X509Certificate cert = X509Certificate.getInstance(certData);
//        signCert.checkValidity();
//
//        //获取服务器公钥
//        X509Certificate x509Certificate = null;
//        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
//        FileInputStream fileInputStreamt = new FileInputStream(citiKeyFileString);
//        x509Certificate = (X509Certificate) certificateFactory.generateCertificate(fileInputStreamt);
//        fileInputStreamt.close();
//        x509Certificate.checkValidity();
//        PublicKey publicEncryptKey = x509Certificate.getPublicKey();
//
//        JsonWebSignature jwsignature = new JsonWebSignature();
//        jwsignature.setPayload(requestPayload);
//        jwsignature.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
//        jwsignature.setKey(privateSignKey);
//        String signedRequest = jwsignature.getCompactSerialization();
//
//       /* X509Certificate encryptCert = (X509Certificate) ks.getCertificate(citiEncryptKeyAlias);
//        encryptCert.checkValidity();
//        PublicKey publicEncryptKey = encryptCert.getPublicKey();
//*/
//        JsonWebEncryption jwEncrypt = new JsonWebEncryption();
//        jwEncrypt.setPlaintext(signedRequest);
//        jwEncrypt.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.RSA_OAEP_256);
//        jwEncrypt.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
//        jwEncrypt.setKey(publicEncryptKey);
//        String payloadSignedEncrypted = jwEncrypt.getCompactSerialization();
//        return payloadSignedEncrypted;
//    }
//
//
//    public static String encryptionXML(String requestXmlPayload) throws Exception{
//        KeyStore ks = KeyStore.getInstance("JKS");
//        FileInputStream fis = new FileInputStream(keyStoreFilePath);
//        ks.load(fis, keyStorePwd.toCharArray());
//        fis.close();
//
//        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//        factory.setNamespaceAware(true);
//        DocumentBuilder builder = factory.newDocumentBuilder();
//        Document xmlDoc = builder.parse(new InputSource(new StringReader(requestXmlPayload)));
//
//        PrivateKey privateSignKey = (PrivateKey) ks.getKey(clientSignKeyAlias, keyStorePwd.toCharArray());
//        X509Certificate signCert = (X509Certificate)ks.getCertificate(clientSignKeyAlias);
//        signCert.checkValidity();
//
//        org.apache.xml.security.Init.init();
//        ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds");
//        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//        dbf.setNamespaceAware(true);
//        Element root = xmlDoc.getDocumentElement();
//        XMLSignature sig = new XMLSignature(xmlDoc, "file:", XMLSignature.ALGO_ID_SIGNATURE_RSA);
//        root.appendChild(sig.getElement());
//        Transforms transforms = new Transforms(xmlDoc);
//        transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
//        transforms.addTransform(Transforms.TRANSFORM_C14N_OMIT_COMMENTS);
//        sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
//        KeyInfo info = sig.getKeyInfo();
//        X509Data x509data = new X509Data(xmlDoc);
//        x509data.add(new XMLX509IssuerSerial(xmlDoc, signCert));
//        x509data.add(new XMLX509Certificate(xmlDoc,signCert));
//        info.add(x509data);
//        sig.sign(privateSignKey);
//
//
//        //获取服务器公钥
//        X509Certificate x509Certificate = null;
//        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
//        FileInputStream fileInputStreamt = new FileInputStream(citiEncryptFileString);
//        x509Certificate = (X509Certificate) certificateFactory.generateCertificate(fileInputStreamt);
//        fileInputStreamt.close();
//        x509Certificate.checkValidity();
//        PublicKey publicEncryptKey = x509Certificate.getPublicKey();
//
//        String jceAlgorithmName = "DESede";
//        KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
//        Key symmetricKey = keyGenerator.generateKey();
//        String algorithmURI = XMLCipher.RSA_v1dot5;
//        XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI);
//        keyCipher.init(XMLCipher.WRAP_MODE, publicEncryptKey);
//        EncryptedKey encryptedKey = keyCipher.encryptKey(xmlDoc, symmetricKey);
//        Element rootElement = xmlDoc.getDocumentElement();
//        algorithmURI = XMLCipher.TRIPLEDES;
//        XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI);
//        xmlCipher.init(XMLCipher.ENCRYPT_MODE, symmetricKey);
//        EncryptedData encryptedData = xmlCipher.getEncryptedData();
//        KeyInfo keyInfo = new KeyInfo(xmlDoc);
//        keyInfo.add(encryptedKey);
//        encryptedData.setKeyInfo(keyInfo);
//        xmlCipher.doFinal(xmlDoc, rootElement, false);
//
//        TransformerFactory tf = TransformerFactory.newInstance();
//        Transformer transformer = tf.newTransformer();
//        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//        StringWriter writer = new StringWriter();
//        transformer.transform(new DOMSource(xmlDoc), new StreamResult(writer));
//        String signedEncryptedRequest = writer.getBuffer().toString();
//        return  signedEncryptedRequest;
//    }
//
//
//    public static String decryptionXML(String responseXMLPayload) throws Exception{
//        String response = "";
//        KeyStore ks = KeyStore.getInstance("JKS");
//        FileInputStream fis = new FileInputStream(keyStoreFilePath);
//        ks.load(fis, keyStorePwd.toCharArray());
//        fis.close();
//
//        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//        factory.setNamespaceAware(true);
//        DocumentBuilder builder = factory.newDocumentBuilder();
//        Document xmlDoc = builder.parse(new InputSource(new StringReader(responseXMLPayload)));
//
//        PrivateKey privateDecryptKey = (PrivateKey) ks.getKey(clientSignKeyAlias, keyStorePwd.toCharArray());
//        X509Certificate decryptCert = (X509Certificate)ks.getCertificate(clientSignKeyAlias);
//        decryptCert.checkValidity();
//
//        org.apache.xml.security.Init.init();
//
//        Element docRoot = xmlDoc.getDocumentElement();
//        Node dataEL = null;
//        Node keyEL = null;
//        if("http://www.w3.org/2001/04/xmlenc#".equals(docRoot.getNamespaceURI()) && "EncryptedData".equals(docRoot.getLocalName()))
//        {
//            dataEL = docRoot;
//        }
//        else
//        {
//            NodeList childs = docRoot.getElementsByTagNameNS("http://www.w3.org/2001/04/xmlenc#", "EncryptedData");
//            if(childs == null || childs.getLength() == 0){
//                throw new Exception("Encrypted Data not found on XML Document while parsing  to decrypt");
//            }
//            dataEL = childs.item(0);
//        }
//        if(dataEL == null){
//            throw new Exception("Encrypted Data not found on XML Document while parsing  to decrypt");
//        }
//        NodeList keyList = ((Element)dataEL).getElementsByTagNameNS("http://www.w3.org/2001/04/xmlenc#", "EncryptedKey");
//        if(keyList == null || keyList.getLength() == 0){
//            throw new Exception("Encrypted Key not found on XML Document while parsing  to decrypt");
//        }
//        keyEL = keyList.item(0);
//        XMLCipher cipher =  XMLCipher.getInstance();
//        cipher.init(XMLCipher.DECRYPT_MODE, null);
//        EncryptedData encryptedData =  cipher.loadEncryptedData(xmlDoc, (Element)dataEL);
//        EncryptedKey encryptedKey =  cipher.loadEncryptedKey(xmlDoc, (Element)keyEL);
//        Document decryptedDoc = null;
//        if (encryptedData != null && encryptedKey != null)
//        {
//            String encAlgoURL = encryptedData.getEncryptionMethod().getAlgorithm();
//            XMLCipher keyCipher =  XMLCipher.getInstance();
//            keyCipher.init(XMLCipher.UNWRAP_MODE, privateDecryptKey);
//            Key encryptionKey =  keyCipher.decryptKey( encryptedKey, encAlgoURL );
//            cipher =  XMLCipher.getInstance();
//            cipher.init(XMLCipher.DECRYPT_MODE, encryptionKey);
//            decryptedDoc = cipher.doFinal(xmlDoc, (Element)dataEL);
//        }
//        decryptedDoc.normalize();
//
//        //获取服务器签名公钥
//        X509Certificate signVerifyCert = null;
//        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
//        FileInputStream fileInputStreamt = new FileInputStream(citiSignFileString);
//        signVerifyCert = (X509Certificate) certificateFactory.generateCertificate(fileInputStreamt);
//        fileInputStreamt.close();
//        signVerifyCert.checkValidity();
//
//        boolean verifySignStatus=false;
//        NodeList sigElement = decryptedDoc.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature");
//        if (sigElement == null || sigElement.getLength() == 0) {
//            throw new Exception("No XML Digital Signature Found - unable to check the signature");
//        }
//        else{
//            String BaseURI = "file:";
//            XMLSignature signature = new XMLSignature((Element)sigElement.item(0), BaseURI);
//            KeyInfo keyInfo = signature.getKeyInfo();
//            if (keyInfo == null)
//            {
//                throw new Exception("Could not locate KeyInfo element - unable to check the signature");
//            }
//            else
//            {
//                if (keyInfo.containsX509Data())
//                {
//                    X509Certificate certFromDoc = keyInfo.getX509Certificate();
//                    if(certFromDoc !=null){
//                        int enCodeCertLengthFrmDocCert = certFromDoc.getEncoded().length;
//                        int enCodeCertLengthTobeValidated = signVerifyCert.getEncoded().length;
//                        if(enCodeCertLengthFrmDocCert == enCodeCertLengthTobeValidated)
//                        {
//                            verifySignStatus = signature.checkSignatureValue(signVerifyCert);
//                        }else{
//                            throw new Exception("Signature Verification Failed as Cert available in XML & configured on Plugin Properties are different");
//                        }
//                    }
//                }
//                else{
//                    PublicKey pk = keyInfo.getPublicKey();
//                    if (pk != null)
//                    {
//                        verifySignStatus = signature.checkSignatureValue(signVerifyCert);
//                    }else{
//                        throw new Exception("X509 cert and PublicKey not found on signature of XML");
//                    }
//                }
//            }
//        }
//
//        if(!verifySignStatus){
//            throw new Exception("XML Signature Verification Failed");
//        }
//        TransformerFactory tf = TransformerFactory.newInstance();
//
//        Transformer transformer = tf.newTransformer();
//
//        DOMSource source = new DOMSource(decryptedDoc);
//
//        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
//
//        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
//
//        StringWriter writer = new StringWriter();
//
//        StreamResult result = new StreamResult(writer);
//
//        transformer.transform(source, result);
//
//        String output = writer.getBuffer().toString();
//        if(output.contains("</TxSts>")){
//              response = output;
//        }
//        else if(output.contains("<Response")){
//            String base64str = output.substring(output.indexOf("PD94b"),output.indexOf("<Signature"));
//            //base64解密
//            byte[] ate = Base64.decodeBase64(base64str);
//            response = new String(ate);
//        }else{
//            response = output.split("<access_token>")[1].split("</access_token>")[0];
//        }
//        return response;
//    }
//
//
//    public static String decryptionJSON(String responsePayload) throws Exception{
//        KeyStore ks = KeyStore.getInstance("JKS");
//        FileInputStream fis = new FileInputStream(keyStoreFilePath);
//        ks.load(fis, keyStorePwd.toCharArray());
//        fis.close();
//
//        PrivateKey privateDecryptKey = (PrivateKey) ks.getKey(clientSignKeyAlias, keyStorePwd.toCharArray());
//        X509Certificate decryptCert = (X509Certificate)ks.getCertificate(clientSignKeyAlias);
//        decryptCert.checkValidity();
//
//
//        JsonWebEncryption jwEncryption = new JsonWebEncryption();
//        jwEncryption.setKey(privateDecryptKey);
//        jwEncryption.setCompactSerialization(responsePayload);
//        String decryptedResponse = jwEncryption.getPlaintextString();
//
//        X509Certificate signVerifyCert = (X509Certificate) ks.getCertificate(clientSignKeyAlias);
//        signVerifyCert.checkValidity();
//        PublicKey signVerifyKey = signVerifyCert.getPublicKey();
//
//        JsonWebSignature jwSignature = new JsonWebSignature();
//        jwSignature.setKey(signVerifyKey);
//        jwSignature.setCompactSerialization(decryptedResponse);
//        String verifiedResponse = jwSignature.getPayload();
//        return verifiedResponse;
//    }
//
//    public static ClientResponse post(String oAuthPayloadSignedEncrypted,String reqUrl,String token) throws Exception{
//        String sslCertFilePath = "E:\\ssl\\20200117.p12";
//        //String sslCertFilePath = "D:\\name.jks";
//        String certPwd = "123456";
//        //String clientID = "8aced9e3-4b06-4b89-b9b5-a210917cd193";
//       // String clientSecret = "G3dG3dQ1hP8wR0oK0kK6wR3sV3yO7iF8vA8aK0sQ1fG5fJ6oQ0";
//
//        KeyStore clientStore = KeyStore.getInstance("PKCS12");
//        clientStore.load(new FileInputStream(sslCertFilePath), certPwd.toCharArray());
//        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
//        kmf.init(clientStore, certPwd.toCharArray());
//        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
//        sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
//        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
//        Client client = new Client(new URLConnectionClientHandler(
//                new HttpURLConnectionFactory() {
//                    Proxy proxy = null;
//                    public HttpURLConnection getHttpURLConnection(URL url)
//                            throws IOException {
//                        proxy=Proxy.NO_PROXY;
//                        return (HttpURLConnection) url.openConnection(proxy);
//                    }
//                }), new DefaultClientConfig());
//        WebResource webResource = client.resource(reqUrl);
//        WebResource.Builder builder = webResource.type(MediaType.APPLICATION_XML);
//        builder.header("payloadType","urn:iso:std:iso:20022:tech:xsd:pain.001.001.03");
//        builder.header(HttpHeaders.AUTHORIZATION, "Bearer " + token);
//        //builder.header("clientId",clientID);
//        ClientResponse clientResponse = null;
//        String response = "";
//        try{
//            clientResponse = builder.post(ClientResponse.class,oAuthPayloadSignedEncrypted);
//            //clientResponse = builder.get(ClientResponse.class);
//        //    WriteBankLogLn("发送给银行的报文："+JSON.toJSONString(clientResponse.getHeaders()));
//            System.out.println(JSON.toJSONString(clientResponse.getHeaders()));
//            System.out.println(JSON.toJSONString(clientResponse.getResponseStatus()));
//            System.out.println(JSON.toJSONString(clientResponse.getStatus()));
//            //提取加密信息
//            //response = response.split("<xenc:CipherValue>")[2].split("</xenc:CipherValue>")[0];
//
//        }catch (Exception e){
//            // System.out.println(JSON.toJSONString(clientResponse.getHeaders()));
//            // System.out.println(JSON.toJSONString(clientResponse.getStatus()));
//            e.printStackTrace();
//        }
//        return clientResponse;
//    }
//
//    public static String get(String oAuthPayloadSignedEncrypted,String reqUrl,String token) throws Exception{
//        String sslCertFilePath = "E:\\ssl\\20200117.p12";
//        //String sslCertFilePath = "D:\\name.jks";
//        String certPwd = "123456";
//        String clientID = "8aced9e3-4b06-4b89-b9b5-a210917cd193";
//        String clientSecret = "G3dG3dQ1hP8wR0oK0kK6wR3sV3yO7iF8vA8aK0sQ1fG5fJ6oQ0";
//
//        KeyStore clientStore = KeyStore.getInstance("PKCS12");
//        clientStore.load(new FileInputStream(sslCertFilePath), certPwd.toCharArray());
//        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
//        kmf.init(clientStore, certPwd.toCharArray());
//        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
//        sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
//        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
//        Client client = new Client(new URLConnectionClientHandler(
//                new HttpURLConnectionFactory() {
//                    Proxy proxy = null;
//                    public HttpURLConnection getHttpURLConnection(URL url)
//                            throws IOException {
//                        proxy=Proxy.NO_PROXY;
//                        return (HttpURLConnection) url.openConnection(proxy);
//                    }
//                }), new DefaultClientConfig());
//        WebResource webResource = client.resource(reqUrl);
//        WebResource.Builder builder = webResource.type(MediaType.APPLICATION_XML);
//        builder.header(HttpHeaders.AUTHORIZATION, "Bearer " + token);
//        //builder.header("clientId",clientID);
//        ClientResponse clientResponse = null;
//        String response = "";
//        try{
//            clientResponse = builder.post(ClientResponse.class,oAuthPayloadSignedEncrypted);
//            //clientResponse = builder.get(ClientResponse.class);
//            System.out.println(JSON.toJSONString(clientResponse.getHeaders()));
//            System.out.println(JSON.toJSONString(clientResponse.getResponseStatus()));
//            System.out.println(JSON.toJSONString(clientResponse.getStatus()));
//            response = clientResponse.getEntity(String.class);
//            System.out.println("银行返回的报文："+response);
//            //提取加密信息
//            //response = response.split("<xenc:CipherValue>")[2].split("</xenc:CipherValue>")[0];
//
//        }catch (Exception e){
//            // System.out.println(JSON.toJSONString(clientResponse.getHeaders()));
//            // System.out.println(JSON.toJSONString(clientResponse.getStatus()));
//            e.printStackTrace();
//        }
//        return response;
//    }
//
//    public static String authentication(String oAuthPayloadSignedEncrypted,String reqUrl) throws Exception{
//
//
//        String sslCertFilePath = "E:\\ssl\\20200117.p12";
//        String certPwd = "123456";
//        String oAuthURL = "https://tts.apib2b.citi.com/citiconnect/prod/authenticationservices/v2/oauth/token";
//        String clientID = "d390fa31-3254-4b5b-9991-ff7d610633f7";//"8aced9e3-4b06-4b89-b9b5-a210917cd193";
//        String clientSecret = "L5wL3eO8xU2dX6pA7gL8lM5jK5iI1uP3dL2yB2sS6tH0iM2cE0";//"G3dG3dQ1hP8wR0oK0kK6wR3sV3yO7iF8vA8aK0sQ1fG5fJ6oQ0";
//
//        KeyStore clientStore = KeyStore.getInstance("PKCS12");
//        clientStore.load(new FileInputStream(sslCertFilePath), certPwd.toCharArray());
//        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
//        kmf.init(clientStore, certPwd.toCharArray());
//        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
//        sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
//        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
//        Client client = new Client(new URLConnectionClientHandler(
//                new HttpURLConnectionFactory() {
//                    Proxy proxy = null;
//                    public HttpURLConnection getHttpURLConnection(URL url)
//                            throws IOException {
//                            proxy=Proxy.NO_PROXY;
//                        return (HttpURLConnection) url.openConnection(proxy);
//                    }
//                }), new DefaultClientConfig());
//        WebResource webResource = client.resource(oAuthURL);
//        WebResource.Builder builder = webResource.type(MediaType.APPLICATION_XML);
//        builder.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64.encodeBase64String((clientID+":"+clientSecret).getBytes()).replaceAll("(\\r|\\n)", ""));
//        ClientResponse clientResponse = null;
//        String response = "";
//        try{
//            clientResponse = builder.post(ClientResponse.class,oAuthPayloadSignedEncrypted);
//            System.out.println(JSON.toJSONString(clientResponse.getHeaders()));
//            System.out.println(JSON.toJSONString(clientResponse.getResponseStatus()));
//            System.out.println(JSON.toJSONString(clientResponse.getStatus()));
//            response = clientResponse.getEntity(String.class);
//            System.out.println("银行返回的报文："+response);
//            //提取加密信息
//             //response = response.split("<xenc:CipherValue>")[2].split("</xenc:CipherValue>")[0];
//
//        }catch (Exception e){
//           // System.out.println(JSON.toJSONString(clientResponse.getHeaders()));
//           // System.out.println(JSON.toJSONString(clientResponse.getStatus()));
//            e.printStackTrace();
//        }
//        return response;
//    }
//
//}
